package com.tianruan.dc.modules.sys.user.mapper;

import com.tianruan.dc.modules.sys.user.entity.dto.RegisterDTO;
import com.tianruan.dc.modules.userinfo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface RegisterMapper {

    /**
     * 注册存入数据
     * @param id
     */
    @Insert("insert into t_sys_user (id,name,username,password,dept_id,position,create_date,phone,status,remarks,del_flag)" +
            "values " +
            "(#{id},#{name},#{username},#{password},#{officeId},#{post},#{createDate},#{phone},#{status},#{remarks},#{delFlag})")
    void save(RegisterDTO id);

    /**
     * 根据用户名查询id
     * @param username
     * @return
     */
    @Select("select id from t_sys_user where username = #{username}")
    String getIdByUsername(String username);


    /**
     * 添加角色
     * @param id
     */
    @Insert("insert into t_sys_user_role (user_id,role_id) " +
            "values " +
            "(#{id},#{roleId})")
    void role(String id, String roleId);

    /**
     * 微信小程序添加角色
     * @param id
     * @param roleId
     */
    @Insert("insert into t_sys_user_role (user_id,role_id) " +
            "values " +
            "(#{id}, #{roleId})")
    void WXrole(String id, String roleId);

    @Insert("insert into t_sys_user_info (id,user_id,name,type,create_date,phone,del_flag)" +
            "values " +
            "(#{id},#{userId},#{name},#{type},#{createDate},#{phone},#{delFlag})")
    void insert(User user);

    @Select("select id from t_sys_user where name = #{name}")
    String getIdByName(String name);


    /**
     * 角色授权
     * @param permissionId
     * @param userId
     */
//    @Insert("insert into t_sys_user_permission (user_id, permission_id) " +
//            "values " +
//            "(#{idByUsername},#{permissionId})")
//    void permission(Integer permissionId, String userId);
}
